<?php

class Antz_Form_Components_CheckboxGroup extends Antz_Form_Component
{
    protected $components = array();
    protected $type = 'checkboxGroup';
    public function add($name, $label, $value, $checked=false, $aftertext=''){
        $checked = (bool) $checked;
        $this->name = $name;
        $this->type = 'checkboxGroup';
        $this->components[] = Antz::newObject('Antz_Form_Components_Checkbox', array($name, $label, $value, $checked, $aftertext));
        return $this->components[(count($this->components)-1)];
    }

    public function render(){
        if($this->isXhtml) $closeTag = ' />';
        else $closeTag = '>';
        $returnString = "\n".'<div class="checkboxGroup" id="'.$this->getId().'"'.'>';
        foreach($this->components as $component){
            $returnString .= "\n  ".$component->render();
        };
        $returnString .= "\n".'</div>';
        if($this->wrap) $returnString = $this->wrap($returnString);
        return $returnString;
    }

    public function addCheckAll(){
        $this->components[] = Antz::newObject('Antz_Form_Components_LongTag', array('p', '<a href="javascript: AntzForm.toggleCheckAll(\''.$this->getId().'\')">Check / Uncheck All</a>'));
    }
}
